<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Shared Area Information Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function submitForm() {
  		var shareAreaUID = "<s:property value='shareAreaUID' />";
  		//表单信息
  		var areaName = $("input[name='areaName']").val(); 
  		var projectID = $("select[name='shareArea.projectID']").val();
  		var communityID = $("select[name='shareArea.communityID']").val();
  		var binaryPercent = $("input[name='binaryPercent']").val();
  		var measureChargePrice = $("input[name='measureChargePrice']").val();
  		var measureUnit = $("select[name='shareArea.measureUnit']").val();
  		var areaChargePrice = $("input[name='areaChargePrice']").val();
  		var startDate = $("input[name='startDate']").val();
  		var endDate = $("input[name='endDate']").val();
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"beshs/shareAreaActionJson!saveOrUpdateShareArea.do?date="+new Date(), {
  			"shareArea.id": shareAreaUID,
  			"shareArea.areaName": areaName,
  			"shareArea.projectID": projectID,
  			"shareArea.communityID": communityID,
  			"shareArea.binaryPercent": binaryPercent,
  			"shareArea.measureChargePrice": measureChargePrice,
  			"shareArea.measureUnit": measureUnit,
  			"shareArea.areaChargePrice": areaChargePrice,
  			"shareArea.startDate": startDate,
  			"shareArea.endDate": endDate,
  			"shareArea.remark": remark
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Successful Operation！", function() {
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["shareAreaList"].location = path + "beshs/shareAreaAction!queryShareAreaPage.do?date"+new Date();
  					parent.layer.close(index);
  				});
  			} else {
  				Dialog.alert(data.msg);
  			}
  		});
  	}
  	
  	$(function(){
		$("form[name='shareAreaForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
				//校验采暖季起止日期
				var startDate = $("input[name='startDate']").val();
  				var endDate = $("input[name='endDate']").val();
  				if(startDate > endDate) {
  					Dialog.alert("Please make sure that the end date is later than the start date！");
  				} else {
  					submitForm();
  				}
				return true; //这里明确return false的话表单将不会提交
			}
		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#" name="shareAreaForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
          			<th>Shared Area Name：</th>
          			<td colspan="3">
          				<input name="areaName" type="text" class="s_input" value="<s:property value='shareArea.areaName' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{1,60}$/" sucmsg="Shared Area Name Verification Passed！" nullmsg="Please enter shared area name！" errormsg="Shared area name only can be composed of letters,numbers and dashes within 1~60 characters！"/>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Shared area name only can be composed of letters,numbers and dashes within 1~60 characters！</div></td>
        		</tr>
        		<tr>
          			<th>Project：</th>
          			<td><s:select name="shareArea.projectID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"
          					datatype="*" nullmsg="Please select the project！" errormsg="Please select the project！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>District：</th>
          			<td>
          				<script type="text/javascript">
          					function reloadCommunitys(projectUID, communityUID) {
          						$("select[name='shareArea.communityID']").children("option").slice(1).remove();
	      						if(projectUID!=null && projectUID!="") {
	      							$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
	      								projectUID: projectUID
	      							}, function(data){
	      								for(var index=0; index<data.length; index++) {
	      									if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
		        								$("select[name='shareArea.communityID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
		        							} else {
		        								$("select[name='shareArea.communityID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
		        							}
	      								}
	      							});
	      						}
          					}
          					
          					$(function() {
	      						$("select[name='shareArea.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='shareArea.communityID']").val();
			        				reloadCommunitys(projectUID, communityUID);
			        			});
	      					});
          				</script>
          				<s:select name="shareArea.communityID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel" 
          					datatype="*" nullmsg="Please enter district name！" errormsg="Please enter district name！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Two-part Price Proportion：</th>
          			<td><input name="binaryPercent" type="text" class="s_input" value="<s:property value='shareArea.binaryPercent' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Two-part Price Proportion Verification Passed！" nullmsg="Please enter two-part price proportion！" errormsg="Please enter integral or float type value！" />%
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
            		<th>Heat Price by Area：</th>
          			<td><input name="areaChargePrice" type="text" class="s_input" value="<s:property value='shareArea.areaChargePrice' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Heat Price by Area Verification Passed！" nullmsg="Please enter two-part price proportion！" errormsg="Please enter integral or float type value！"/>元/m&sup2;
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
        		</tr>
        		<tr>
          			<th colspan="2">Heat Price by Metering：</th>
          			<td colspan="2">
          				<input name="measureChargePrice" type="text" class="s_input" value="<s:property value='shareArea.measureChargePrice' />" 
          						datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Heat price by metering verification passed！" nullmsg="Please enter heat price by metering！" errormsg="Please enter integral or float type value！"/>
            			<s:select name="shareArea.measureUnit" list="#{'1':'元/MWh', '2':'元/kWh', '3':'元/Gj'}" cssClass="s_sel"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
        		</tr>
        		<tr>
        			<th>Heating Season Start Date</th>
        			<td>
        			<input id="area_startDate" name="startDate" class="Wdate" value="<s:date name='shareArea.startDate' format='yyyy-MM-dd' nice='false' />" sucmsg="Confirmation of the start date of the heating season！" nullmsg="Please enter the start date of the heating season！" errormsg="Please enter date and time in correct format such as--2014-07-19！" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
        			
<%--         				<input name="startDate" id="area_startDate" type="text" class="s_input" value="<s:date name='shareArea.startDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')"  --%>
<!--         					datatype="/^(\d{4})-(\d{1,2})-(\d{1,2})$/" sucmsg="Heating season start date verification passed！" nullmsg="Please enter heating season start date ！" errormsg="Please enter date and time in correct format such as-- 2014-07-19！" readonly/> -->
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('area_startDate','yyyy-MM-dd')"/>&nbsp;<span style="color:#FF0000;">*</span> --%>
        				<div class="Validform_checktip"></div></td>
        			<th>Heating Reason End Date</th>
        			<td>
        			<input id="area_endDate" name="endDate" class="Wdate" value="<s:date name='shareArea.endDate' format='yyyy-MM-dd' nice='false' />" sucmsg="Heating reason end date verification passed！" nullmsg="Please enter heating reason end date！" errormsg="Please enter date and time in correct format such as-- 2014-07-19！" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
        			
<%--         				<input name="endDate" id="area_endDate" type="text" class="s_input" value="<s:date name='shareArea.endDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')"  --%>
<!--         					datatype="/^(\d{4})-(\d{1,2})-(\d{1,2})$/" sucmsg="Heating reason end date verification passed！" nullmsg="Please enter heating reason end date！" errormsg="Please enter date and time in correct format such as-- 2014-07-19！" readonly/> -->
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('area_endDate','yyyy-MM-dd')"/>&nbsp;<span style="color:#FF0000;">*</span> --%>
        				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="remark" cols="45" rows="3" 
          					datatype="*1-200" ignore="ignore" errormsg="Invalid input!  please input valid content ,no more than 200pcs character">
          					<s:property value='shareArea.remark' /></textarea>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
